package com.bnz.controller;

import com.bnz.Entity.User;
import com.bnz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xy
 * @date 2022/10/27
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    //1. 列表学生
    @GetMapping("list")
    public List<User> list(){
        //1.1 查询所有学生
        List<User> users = userService.findAll();
        return users;
    }

    //2. 添加学生
    @PostMapping("add")
    public String add(@RequestBody User user){
        userService.add(user);
        return "添加";
    }

    //3. 修改学生
    @PutMapping("update")
    public String update(@RequestBody User user){
        userService.updata(user);
        return "修改";
    }

    //4. 删除学生
    @DeleteMapping("delete/{sid}")
    public String  delete(@PathVariable Integer sid){
        userService.delete(sid);
        return "删除";
    }
}
